<template>
  <div>
    <slot name="mouseMove" v-bind="mouse"></slot>
    <div class="box" ref="box"></div>
  </div>
</template>
<script>
export default {
  name: "mousePosition",
  data() {
    return {
      mouse: {
        x: 0,
        y: 0,
      },
    };
  },
  mounted() {
    window.addEventListener("mousemove", this.update);
  },
  unmounted() {
    window.removeEventListener("mousemove");
  },
  methods: {
    update(e) {
      this.mouse.x = e.x;
      this.mouse.y = e.y;
    },
  },
};
</script>
<style lang="less" scoped>
.box {
  position: absolute;
  top: 10px;
  left: 10px;
  width: 50px;
  height: 50px;
  border: 1px solid gray;
  border-radius: 5px;
}
</style>